﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SIS.DataAccess;
namespace SIS.Business
{
	public class Student
	{
		#region Properties
		public string ID
		{
			get
			{
				return _this[DataAccess.Student.STUDENT_ID] as string;
			}
			set
			{
				if (value != null && value != ID)
				{
					_this[DataAccess.Student.STUDENT_ID] = value;
				}
				else throw new ArgumentNullException("Student::ID");
			}
		}

		public string Name
		{
			get
			{
				return _this[DataAccess.Student.STUDENT_NAME] as string;
			}
			set
			{
				if (value != null && value != Name)
				{
					_this[DataAccess.Student.STUDENT_NAME] = value;
				}
				else throw new ArgumentNullException("Student::Name");
			}
		}

		public string DepartmentName
		{
			get
			{
				return _this[DataAccess.Student.DEPARTMENT_NAME] as string;
			}
			set
			{
				if (value != null && value != DepartmentName)
				{
					_this[DataAccess.Student.DEPARTMENT_NAME] = value;
				}
				else throw new ArgumentNullException("Student::Name");
			}
		}

		public int TotalCredit
		{
			get
			{

				return (_this[DataAccess.Student.TOTAL_CREDIT] == null) ? 0 : (int)_this[DataAccess.Student.TOTAL_CREDIT];
			}
			set
			{
				if (value != TotalCredit)
				{
					_this[DataAccess.Student.TOTAL_CREDIT] = value;
				}
			}
		}
		#endregion
		#region Constructors
		private SIS.DataAccess.Entities.Student _this;
		public Student()
		{
			this._this = SIS.DataAccess.Student.Instance.NewRow() as SIS.DataAccess.Entities.Student;
		}
		
		#endregion
		#region Methods

		public Student(SIS.DataAccess.Entities.Student instance)
		{
			this._this = instance;
		}
		public static System.Data.DataTable GetStudents()
		{
			return SIS.DataAccess.Student.Instance;
		}
		public static Student GetStudent(string studentID)
		{
			return new Student(SIS.DataAccess.Student.GetStudent(studentID));
		}

		public bool Insert()
		{
			this._this.Table.Rows.Add(_this);
			return (this._this.Table as SIS.DataAccess.Student).Insert();
		}

		public bool Update()
		{
			return (this._this.Table as DataAccess.Student).Update();
		}

		public new bool Delete()
		{
			(this._this as System.Data.DataRow).Delete();
			return (this._this.Table as DataAccess.Student).Delete();
		}
		#endregion
	}
}
